package server.controller.goodController;

import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.InfoUtils.InfoEnum;
import server.util.InfoUtils.InfoUtil;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/getGoodByKey")
public class GetGoodByKeyServlet extends HttpServlet {
    private static final long serialVersionUID = 2730018400977980256L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Info info = null;
        String key = req.getParameter("key");
        String page = req.getParameter("page");
        String num = req.getParameter("num");

        if (key == null) {
            key = "";
        }
        if (!MyUtils.NOTNULL(page, num)) {
            info = InfoUtil.getInfo(InfoEnum.PARAMS_NULL);
        } else {
            info = ModelFactory.getGoodModel().getGoodsByKey(key,Integer.parseInt(page),Integer.parseInt(num));
        }
        ResponseUtil.responseMessage(resp, info);
    }

}
